package utility;

import java.util.List;
import main.Building;
import java.math.*;

public class Support {

	public static int calculateArea(List<Building> listOfBuildings) {
		int sumArea = 0;
		for (Building b : listOfBuildings) {
			sumArea += buildingArea(b);
		}
		return sumArea;
	}

	public static int buildingArea(Building building) {
		return building.x * building.y;
	}

	public static void setSquareLikeBuildingsPos(List<Building> orderedHeight) {
		int sumArea = calculateArea(orderedHeight);
		int widht = (int) Math.sqrt(sumArea);
		int maxY = 0;
		int aktY = 0;
		int aktX = 0;
		for (Building b : orderedHeight) {
			if (b.y > maxY) {
				maxY = b.y;
			}
			b.setxPos(aktX);
			b.setyPos(aktY);
			aktX += b.x;
			if (aktX > widht) {
				aktY += maxY;
				aktX = 0;
			}
		}
	}

	public static void setLefele(List<Building> orderedHeight){
		int sumArea = calculateArea(orderedHeight);
		int widht = (int)Math.sqrt(sumArea);
		int minY = 0;
		int aktY = 0;
		int aktX = 0;
 		for(Building b : orderedHeight){
 			if(b.y > minY){
 				minY = b.y;
 			}
			b.setxPos(aktX);
			b.setyPos(aktY- b.y);
			aktX += b.x;
			if(aktX > widht){
				aktY -= minY;
				aktX = 0;
			}
		}
	}

	public static void setTallBuildingsPos(List<Building> tall) {
		int sumArea = calculateArea(tall);
		int widht = (int) Math.sqrt(sumArea);
		int minX = 0;
		int aktX2 = 0;
		int aktY = 0;
		for (Building b : tall) {
			if (b.x > minX) {
				minX = b.x;
			}
			b.setxPos(aktX2 - b.x);
			b.setyPos(aktY);
			aktY += b.y;
			if (aktY > widht) {
				aktX2 -= minX;
				aktY = 0;
			}
		}
	}

}
